<template>
  <div class="Project">
    <Management>
      <Top
        slot="top"
        @showModel="showModel"
        @showAll="showAll"
        @search="onSearch"
        :add="true"
        :excel="false"
      ></Top>
      <Table
        slot="body"
        :title="columns"
        :tableData="data"
        @edit="edit"
        @del="del"
        @changePage="changePage"
        other-txt="报名"
        @other="outToTab"
        :total="total"
        :current="current"
      ></Table>
    </Management>

    <Dialog :show="isShow" :row="this.row" @confirm="confirm" @cancel="cancel">
      <div slot="form">sd</div>
    </Dialog>
    <signup-dialog
      :show="show"
      :exec="exec"
      :id="id"
      @cancel="signupCancel"
      @confirm="signupConfirm"
    >
      <div slot="signup">ss</div>
    </signup-dialog>
  </div>
</template>

<script>
import Table from "@/components/common/table/Table";
import Management from "components/common/management/Management";
import Top from "./component/Top";
import Dialog from "./component/Dialog";
import signupDialog from "@/views/base/b-job/fair/component/signupDialog";

import {
  getDataByPageAndSize,
  deleteById,
  appendData,
  LikeSearch,
  editData,
  getAllBase
} from "@/network/Base/b-job";

export default {
  components: { Table, Top, Dialog, Management, signupDialog },
  name: "fair",
  data() {
    const columns = [
      {
        title: "id",
        dataIndex: "id",
      },
      {
        title: "年度",
        dataIndex: "year",
      },
      {
        title: "时间",
        dataIndex: "time",
      },
      {
        title: "企业",
        dataIndex: "companyName",
      },
      {
        title: "举办地",
        dataIndex: "place",
      },
      {
        title: "需要的职务",
        dataIndex: "needJob",
        width: 150,
      },
      {
        title: "所需人数",
        dataIndex: "number",
      },
      {
        title: "宣讲人",
        dataIndex: "talking",
      },
      {
        title: "宣讲人岗位",
        dataIndex: "apply",
      },
      {
        title: "宣讲会人数",
        dataIndex: "talkingMember",
      },
      {
        title: "系负责人",
        dataIndex: "leader",
      },
      { title: "所需专业", dataIndex: "profession" },
      { title: "实际录用人数", dataIndex: "factMember" },
      {
        title: "显示结果",
        dataIndex: "status",
      },
    ];
    return {
      AllBase:[],
      columns,
      isShow: false,
      data: [],
      total: 0,
      show: false,
      id: 0,
      row:{},
      exec: false,
      current: 1,
    };
  },
  created() {
    this.init();
  },
  methods: {
    /**
     * @description: 初始化页面
     * @param {Number} page
     * @param {Number} size
     * @author: tao
     */
    async init(page = 1, size = 10) {
      const result = await getDataByPageAndSize(page, size);
      console.log(result);
      if (result.msg) {
        this.data = result.data.slice();
        this.total = result.count;
        this.current = page;
      }
      // this.tableData = this.data;
    },
    async confirm(data) {
      if (data.time == null) {
        const date = new Date();
        const month = date.getMonth() + 1;
        data.time =
          date.getFullYear() +
          "-" +
          month +
          "-" +
          date.getDate() +
          " " +
          date.getHours() +
          ":" +
          date.getMinutes() +
          ":" +
          date.getSeconds();
      }
      this.closeDialog();
      //生成数据
      let formData = new FormData();
      Object.keys(data).forEach((item) => {
        if (item != "edit" && item != "check") {
          formData.append(item, data[item]);
        }
      });
      // console.log(formData.getAll());
      this.$notification["success"]({
        message: "已经更新啦！",
        description: "已更新所有消息",
      });
      if (data.edit) {
        // 编辑数据
        const result = await editData(formData);
        console.log(result);
        if (result.msg) {
          this.init();
        }
      } else {
        //增加数据
        const result = await appendData(formData);
        console.log(result);
        if (result.msg) {
          this.init();
        }
      }
      this.row = {};
    },
    changePage(page) {
      this.init(page);
    },
    async del(e) {
      console.log(e.id);
      const result = await deleteById(e.id);
      console.log(result);
      if (result.msg) {
        this.init();
      }
    },
    async onSearch(value) {
      const result = await LikeSearch(value);
      console.log(result.msg !== undefined);
      if (result.msg !== undefined || result.msg) {
        console.log("11");
        this.$notification["success"]({
          message: "显示成功！",
          description: "已显示所有消息",
        });
        this.data = result.data;
        this.total = result.count;
      } else {
        this.$notification["error"]({
          message: "显示失败！",
          description: "系统维护中~",
        });
      }
    },
    async checked(e) {
      console.log(e);
      this.closeDialog();
    },
    showAll() {
      this.$notification["success"]({
        message: "显示成功！",
        description: "已显示所有消息",
      });
      this.init();
    },
    showModel() {
      this.isShow = true;
      this.row = { time: null };
    },
    edit(e) {
      this.isShow = true;
      this.row = { ...e, edit: true };
      let member = this.row.member;
    },
    handleCheck(e) {
      this.checking = true;
      this.row = { ...e, checking: true };
    },
    cancel() {
      this.closeDialog();
    },
    closeDialog() {
      this.isShow = false;
      this.row = { time: null };
    },
    outToTab(e) {
      console.log(e);
      this.show = true;
      this.exec = true;
      this.id = e.id;
      this.$emit("upTo", { id: e.id });
    },
    signupCancel(e) {
      this.show = false;
    },
    signupConfirm(e) {
      this.show = false;
    },
  },
};
</script>

<style scoped>
</style>